import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useUserStore = defineStore(
  'user',
  () => {
    // 记录用户登录状态
    const token = ref('')

    const setToken = (t: string) => {
      token.value = t
    }
    const userId = ref('')
    const setUserId = (id: string) => {
      userId.value = id
    }
    const clearToken = () => {
      token.value = ''
    }

    return { token, setToken, clearToken, setUserId, userId }
  },
  {
    unistorage: true,
  }
)
